package com.loong.user.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.user.common.backend.param.ManageApiQueryParam;
import com.loong.user.model.ManageAdmin;
import com.loong.user.model.ManageApi;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author: hzp
 * @Date: 2020-10-16 10:28
 */
@Repository
public class ManageApiBusiness extends AbstractBusiness<ManageApi> {
    /**
     * 分页查询
     * @param param
     * @return
     */
    public List<ManageApi> query(ManageApiQueryParam param){
        Condition condition = new Condition(ManageAdmin.class);
        Example.Criteria criteria = condition.createCriteria();
        if (null == param) {
            return findByCondition(condition);
        }
        buildQueryCriteria(param,criteria);
        return findByCondition(condition);
    }
    //这里根据业务需求构造条件
    private void buildQueryCriteria(ManageApiQueryParam param,Example.Criteria criteria){
        if(ObjectUtils.isNotEmpty(param.getName())){
            criteria.andEqualTo("name", param.getName());
        }
        if(ObjectUtils.isNotEmpty(param.getStatus())){
            criteria.andEqualTo("status", param.getStatus());
        }

    }
}
